import React, { Component } from 'react';
import ComponentAdd from '../../../Strategy/Strategy/Component/add';

class PolicyModal extends Component {
  constructor(props) {
    super(props);
    this.state = {
      policyMode: props.actionType
    };
  }

  startEdit = e => {
    e.preventDefault();
    this.setState({
      policyMode: 'update'
    });
  };

  cancelEdit = () => {
    this.setState({
      policyMode: 'detail'
    });
  };

  afterSubmit = () => {
    this.props.afterSubmit && this.props.afterSubmit();
  };

  render() {
    return (
      <div className='stretegy-content' style={{ margin: '-10px 0 30px 0' }}>
        <ComponentAdd
          record={this.props.record}
          id={this.props.record.strategy_id}
          version={this.props.record.version}
          {...this.props}
          actionType={this.state.policyMode}
          changeMode={this.props.model === undefined ? true : this.props.model}
          startEdit={this.startEdit}
          cancelEdit={this.cancelEdit}
          afterSubmit={this.afterSubmit}
        />
      </div>
    );
  }
}

export default PolicyModal;
